package com.nine.algorithm.queue;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author nine
 * @version 1.0
 * @description TODO
 * @date 24/5/8 23:29
 */
public class TestLinkedListQueue {

	@Test
	public void offerLimit(){
		LinkedListQueue<Integer> queue = new LinkedListQueue<>(3);
		queue.offer(1);
		queue.offer(2);
		queue.offer(3);
		assertFalse(queue.offer(4));
		assertFalse(queue.offer(5));
	}

	@Test
	public void offer() {
		LinkedListQueue<Integer> queue = new LinkedListQueue<>();
		queue.offer(1);
		queue.offer(2);
		queue.offer(3);
		queue.offer(4);
		queue.offer(5);

		System.out.println(queue.toString());
		// assertIterableEquals(List.of(1, 2, 3, 4, 5), queue);
	}

	@Test
	public void peek() {
		LinkedListQueue<Integer> queue = new LinkedListQueue<>();
		assertNull(queue.peek());
		queue.offer(1);
		assertEquals(1, queue.peek());
		queue.offer(2);
		// 队列先进先出
		assertEquals(1, queue.peek());
	}

	@Test
	public void poll(){
		LinkedListQueue<Integer> queue = new LinkedListQueue<>();
		queue.offer(1);
		queue.offer(2);
		queue.offer(3);
		queue.offer(4);
		queue.offer(5);
		assertEquals(1, queue.poll());
		assertEquals(2, queue.poll());
		assertEquals(3, queue.poll());
		assertEquals(4, queue.poll());
		assertEquals(5, queue.poll());
		assertNull(queue.poll());
	}

}
